<template>
  <div>
    <h1>登录</h1>
    <p>用户名：<input type="text" v-model="username" /></p>
    <p>密码：<input type="password" v-model="pwd" /></p>
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      username: "",
      pwd: "",
    };
  },
  mounted() {},
  methods: {
    login() {
      this.$axios
        .post("/api/users/login", {
          userName: this.username,
          password: this.pwd,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "001") {
            this.$router.push("/");
           this.$store.commit('login',res.data.user)
          } else {
            alert(res.data.msg);
            this.username='',
            this.pwd=''
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
